<template>
  <el-dialog
    :close-on-click-modal="false"
    :title="form.is_send == 1 ? '批量下载' : '批量发送'"
    v-model="visible"
    align-center
    width="600px"
    destroy-on-close
  >
    <el-form>
      <el-form-item label="开票合同">
        <el-radio-group v-model="form.billing_contract_type" class="ml-4">
          <el-radio
            :value="item.value"
            v-for="item in pdf_excle_list"
            :key="item"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
      </el-form-item>
      <el-form-item label="送货清单">
        <el-radio-group v-model="form.deliver_list_type" class="ml-4">
          <el-radio
            :value="item.value"
            v-for="item in pdf_excle_list"
            :key="item"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
      </el-form-item>
      <el-form-item label="开票清单">
        <el-radio-group v-model="form.billing_list_type" class="ml-4">
          <el-radio
            :value="item.value"
            v-for="item in excle_list"
            :key="item"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
      </el-form-item>
      <el-form-item label="开票明细">
        <el-radio-group v-model="form.billing_detail_type" class="ml-4">
          <el-radio
            :value="item.value"
            v-for="item in excle_list"
            :key="item"
            >{{ item.label }}</el-radio
          >
        </el-radio-group>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="handleClose(false)">取 消</el-button>
      <el-button type="primary" :loading="loading" @click="save"
        >确 定
      </el-button>
    </template>
  </el-dialog>
</template>
<script setup lang="jsx">
import { billFileBatchDownload } from "../api.js";
import { ElMessage } from "element-plus";
import { resMessage } from "@/utils/res";

const pdf_excle_list = [
  { label: "EXCLE", value: 1 },
  { label: "PDF", value: 2 },
];
const excle_list = [{ label: "EXCLE", value: 1 }];
const props = defineProps({
  options: { type: Array, default: () => [] },
});
const emit = defineEmits(["success"]);
// 打开弹窗
const loading = ref(false);
const visible = ref(false);
const form = ref({ audit_result: 1 });
const open = async (val) => {
  visible.value = true;
  form.value = val;
  let arr = [
    "billing_contract_type",
    "deliver_list_type",
    "billing_list_type",
    "billing_detail_type",
  ];
  arr.forEach((key) => {
    form.value[key] = 1;
  });
};
const save = () => {
  loading.value = true;
  billFileBatchDownload(form.value)
    .then((res) => {
      resMessage({
        res,
        success: () => {
          ElMessage.success(
            form.value.is_send == 1
              ? "操作成功,文件下载完成后会发送到飞书账户！"
              : "操作成功,系统处理完成后会以邮件的形式发送到您的邮箱，请注意查收！"
          );
          handleClose(true);
        },
      });
    })
    .finally(() => {
      loading.value = false;
    });
};
const handleClose = (refresh) => {
  form.value = {};
  visible.value = false;
  if (refresh) emit("success");
};
defineExpose({ open });
</script>
<style lang="scss" scoped></style>
